package com.wen.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wen.cms.entity.CrmBanner;
import com.wen.cms.mapper.CrmBannerMapper;
import com.wen.cms.service.CrmBannerService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author wen
 * @since 2021-06-13
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    /**
     * display all banner
     *
     * @return result of request
     */
    @Override
    @Cacheable(key = "'selectIndexList'",value = "banner")
    public List<CrmBanner> selectAll() {
        //        根据id进行降序查询,显示排序后的前两条记录
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
//        last方法,拼接sql语句,可用来操作limit
        wrapper.last("limit 2");
        return baseMapper.selectList(wrapper);
    }
}
